package scene.scene 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import net.message.IMsgBody;
	import scene.gameObject.BasicObject;
	import scene.present.Present;
	import scene.present.PresentManager;
	/**
	 * ...
	 * @author carlor
	 */
	public class SceneData extends Sprite
	{
		protected var _owner    : Sprite;
		protected var _sceneName: String;
		protected var _activate : Boolean;
		protected var _presentManager: PresentManager;
		
		public function SceneData(owner: Sprite, sname: String) 
		{
			_sceneName = sname;
			_owner = owner;
			
			_presentManager = new PresentManager();
			this.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
			this.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
		}
		
		public function dispose(): void
		{
			activate = false;
			_presentManager.clear();
			_presentManager.dispose();
			_presentManager = null;			
			_sceneName = null;
		}
		
		public function update(curTime: int): void
		{
			_presentManager.update(curTime);
		}
		
		public function get sceneName(): String
		{
			return _sceneName;
		}
		
		public function get activate(): Boolean
		{
			return _activate;
		}
		
		public function set activate(value: Boolean): void
		{
			if (_activate == value) return;
			if (value) onActivate();
			else onDeactivate();
		}
		
		protected function onActivate(): void
		{
			_owner.addChild(this);
		}
		
		protected function onDeactivate(): void
		{
			_owner.removeChild(this);
		}
		
		public function handlePacket(op: String, msg: IMsgBody): void
		{
			var method: String = "on" + op;
			if (this[method] != null)
				this[method](msg);
		}
		
		public function mapPos2ScreenPos(p: Point): Point
		{
			return p;
		}
		
		public function scenePos2ScreenPos(p: Point): Point
		{
			return p;
		}
		
		public function resize(): void
		{
			
		}

		public function onKeyDown(e: KeyboardEvent): void
		{
			if (e.keyCode == 32) //space
				Engine.dialogManager.handlePacket("onShowHideUI");
		}
		
		public function onKeyUp(e: KeyboardEvent): void
		{
			
		}
		
		public function addPresent(present: Present): Present
		{
			return _presentManager.addPresent(present);
		}
	}

}